<?php
class ClientsController extends DomController {
	
	public function clients() {
		
		$source = new DomArDataSource( Client::query()->orderBy('t.username DESC'), 40 );

		function meterReaderHandler( $row ) {
			return $row->admin->username; 	
		}
		
		$panel = array(
			'title' => 'Clients',
			'layout' => 'table',
			'layoutConfig' => array(
					'columns' => 1,
			),
			'items' => array(
				array(
					'type' => 'grid',
					'source' => $source,
					'fields' => array(
						array('key' => 'username', 'title' => 'Client id'),
						array('key' => 'electricitySupplier', 'title' => 'Electricity supplier'),
						array('handler' => 'meterReaderHandler', 'title' => 'Meter reader'),
					),
				),
			),
		);
		
		$this->view->contents = DomFg::render( $panel );
	}
}
